import http from "@/http/index.ts"
import {Material, MaterialListParam} from '@/api/material/type.ts'

// 新增物料
export const addApi = (data: Material) => {
    return http.post("/material/createMaterial", data)
}

// 修改物料
export const updateApi = (data: Material) => {
    return http.put("/material/updateMaterial", data)
}

// 删除物料
export const deleteApi = (id: number) => {
    return http.delete(`/material/deleteMaterial/${id}`)
}

// 分页条件查询列表
export const getListApi = (data: MaterialListParam) => {
    return http.get("/material/getMaterialList", data)
}

// 根据物料查询该物料的所有规格列表
export const getSpecificationSimpleListApi = (materialName: string) => {
    return http.get("/material/specificationList?materialName=" + materialName)
}

// 根据ID获取物料详情
export const getByIdApi = (id: number) => {
    return http.get(`/material/getMaterialById/${id}`)
}

// 数据导入
export const importApi = (data: FormData) => {
    return http.post("/material/importMaterial", data, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 数据导出
export const exportApi = (data: MaterialListParam) => {
    return http.get("/material/exportMaterial", data, {
        responseType: 'blob'
    })
}

// 文件上传
export const uploadApi = (data: FormData) => {
    return http.post("/material/upload", data, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

